package com.alibaba.citrus.cr.common.enums.ordercenter;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
public enum SalesOrderCloseEnum {
    NOT_ENOUGH_SHIPPING_STANDARDS("01", "不够发运标准"),
    REGION_REQUEST_STOP_ISSUING("02", "大区要求停发"),
    CHANGE_ORDER_LOGISTICS_LOADING_REMAINING("03", "改单，物流装车剩余"),
    CHANGE_ORDER_CHANGE_ITEM("04", "改单，变换品项"),
    UNPLANNED_DEMAND("05", "计划外需求"),
    UNPLANNED_DEMAND_AFTER_DISCOUNT("06", "打折后计划外需求"),
    OVER_TEN_DAY_REPLY_QUANTITY("07", "超旬回复量"),
    CUSTOMER_REQUIREMENT_TO_VOID_WRONG_ORDER("08", "客户要求作废，录错订单"),
    CUSTOMER_REQUIREMENT_TO_VOID_DATED("09", "客户要求作废，日期陈旧"),
    CUSTOMER_REQUIREMENT_TO_VOID_SELECT_ORIGIN("10", "客户要求作废，挑产地"),
    OUT_OF_STOCK_PRODUCTION_HAS_BEEN_SCHEDULED_ENOUGH("11", "无货，生产已排够"),
    OUT_OF_STOCK_SMALL_ITEMS_ARE_NOT_ENOUGH_TO_START_THE_MACHINE("12", "无货，小品项不够起机量"),
    OUT_OF_STOCK_THE_TOTAL_AREA_HAS_BEEN_REACHED("13", "无货，大区总量已达成"),
    NO_GOODS_OBSOLETE_PRODUCT("14", "无货,淘汰产品"),
    NO_GOODS_NOT_REACHED_ON_THE_WAY("15", "无货，在途未达"),
    NO_GOODS_WAIT_UNTIL_THE_INSULATION_TEST_IS_COMPLETED("16", "无货,保温试验等待放行"),
    NO_MONEY_INSUFFICIENT_MONEY("17", "无款，款不足"),
    ORDER_ACCORDING_NUMBER_PALLETS("18", "按库房托盘数订单"),
    CLOSE_ORDER("19", "关闭订单"),
    CHANGE_ORDERS_DISPATCH_ORDERS_STOCK("20", "改单，调度无货下单"),
    CHANGE_ORDER_NOT_PLACE_ACCORDING_STANDARD("21", "改单，调度未按装箱标准下单"),
    SOME_ITEMS_SHORT_SUPPLY("22", "部分品项差量控制紧俏品"),
    SUSPENSION_GOODS_DELAY_UNLOADING("23", "因不卸车缓发原因停货"),
    BP_NO_GOODS_PRODUCTION("34", "BP无货等生产"),
    BP_OUT_STOCK("35", "BP无货在途"),
    BP_PRODUCT_PENDING("36", "BP产品待检"),
    BP_LESS_BOTTOM_MODELS("37", "BP不足底线车型"),
    BP_REQUIRES_SUSPENSION("38", "BP大区要求停发"),
    BP_NO_PLAN_OVER_PLANNED_DEMAND("39", "BP无计划或超计划需求"),
    BP_NO_PAYMENT_INSUFFICIENT_PAYMENT("40", "BP无款、货款不足"),
    BP_NO_MATCH_DELIVERY_ADDRESS_SYSTEM("41", "BP实际到货地址与系统到货地址不符"),
    BP_RECORDED_REPEATED_FORECASTS("42", "BP客户录错、重复预报"),
    BP_CLOSES_SALES_ORDERS("43", "BP关闭未清销售订单"),
    BP_PRODUCTS_ELIMINATED_MARKET("44", "BP产品已下市淘汰"),
    BP_CUSTOMER_REQUIREMENTS_NOTIFICATIONS("45", "BP客户要求等通知调单"),
    BP_PRODUCTION_DATE_CUSTOMER_NEEDS("46", "BP产品生产日期不符合客户需求"),
    YSL_SUPPLY_PRODUCT_BIG_DATE("Y0", "YSL供应链-产品大日期"),
    YSL_SUPPLY_CHAIN_MONTH_SUPPLY("Y1", "YSL供应链-月中晚供"),
    YSL_SALES_MORE_THAN_DATE("Y2", "YSL销售-超过截单日"),
    YSL_SALES_ORDER_ERROR_REQUEST_ENTRY("Y3", "YSL销售-订单错误，客户要求重录"),
    YSL_SALES_POLICY_REASONS_CHANGE_ORDERS("Y4", "YSL销售-政策原因，改单"),
    YSL_SALES_NOT_ENOUGH_SHIPPING_STANDARDS("Y5", "YSL销售-不够发运标准"),
    YSL_SALES_DIFFERENCE_WAITING_LOANS("Y6", "YSL销售-差款、等银行贷款"),
    YSL_SUPPLY_CHAIN_VOLUME_VOIDED("Y7", "YSL供应链-超计划量作废"),
    YSL_SALES_CUSTOMER_FREEZE("Y8", "YSL销售-客户冻结"),
    YSL_SALES_PRODUCTS_MARKET("Y9", "YSL销售-产品下市"),
    SALES_COMPANY_CLOSE_ITEM("Z1", "销售公司：关闭行项目"),
    SALES_COMPANY_STOCK("Z2", "销售公司：缺货"),
    ;

    private final String code;
    private final String desc;

    SalesOrderCloseEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static SalesOrderCloseEnum of(String code) {
        return Arrays.stream(SalesOrderCloseEnum.values()).filter(source -> Objects.equals(code, source.getCode())).findFirst().orElse(null);
    }

    public static String descByCode(String code) {
        SalesOrderCloseEnum typeEnum = of(code);
        return Objects.nonNull(typeEnum) ? typeEnum.getDesc() : null;
    }

    public static List<String> codes() {
        return Arrays.stream(SalesOrderCloseEnum.values()).map(SalesOrderCloseEnum::getCode).collect(Collectors.toList());
    }
}
